const db = require("../db/operation")
const { collections } = require("../db/config")

function addGoods(goods) {
    console.log("goodsmodule addGoods");
    return db.execCreate(collections.goods,goods);
}

function deleteGoods(id) {
    console.log("goodsmodule deleteGoods");
    return db.execDelete(collections.goods,id);
}

function updataGoods(id,goods) {
    console.log("goodsmodule updataGoods");
    return db.execUpdate(collections.goods,id,goods);
}

function getAllGoods() {
    console.log("goodsmodule getAllGoods");
    return db.execRetrieve(collections.goods)
}

const pagesize = 10

function getGoodsByPage(page) {
    console.log("goodsmodule getGoodsByPage");
    return db.execRetrieve(collections.goods, {}, {
        skip: pagesize * (page - 1),
        limit: pagesize
    })
}


module.exports = {
    addGoods,
    deleteGoods,
    updataGoods,
    getAllGoods,
    getGoodsByPage,
}